package functional.functioncomposition;

/**
 * @ClassName FunctionComposition
 * @PackageName functional.FunctionComposition
 * @projectName myThread
 * @Description 
 * @Author games
 * @Date 2025/8/27 下午1:56
 * @Version 1.0
 */

import java.util.function.*;

public class FunctionComposition {
    /**
     * // f4 = f1.compose(f2).andThen(f3) 的执行过程
     * String input = "GO AFTER ALL AMBULANCES";
     * <p>
     * // 第一步：f2.apply(input) - 截取从索引3开始的字符串
     * String step1 = f2.apply(input);  // "AFTER ALL AMBULANCES"
     * <p>
     * // 第二步：f1.apply(step1) - 替换'A'为'_'并打印
     * String step2 = f1.apply(step1);  // 打印"AFTER ALL AMBULANCES"，返回"__FTER _LL _MBUL_NCES"
     * <p>
     * // 第三步：f3.apply(step2) - 转换为小写
     * String result = f3.apply(step2);  // "__fter _ll _mbul_nces"
     */
    static Function<String, String>
            f1 = s -> {
        System.out.println("****f1" + s);
        return s.replace('A', '_');
    },
            f2 = s -> {
                System.out.println("****f2" + s);
                return s.substring(3);
            },
            f3 = s -> {
                System.out.println("****f3" + s);
                return s.toLowerCase();
            },
            f4 = f1.compose(f2).andThen(f3);

    public static void main(String[] args) {
        System.out.println(
                f4.apply("GO AFTER ALL AMBULANCES"));
    }
}